using System;
using GammaJul.ReSharper.GammaXaml.Highlightings.CSharp;
using GammaJul.ReSharper.GammaXaml.Psi.Xaml;
using JetBrains.Annotations;
using JetBrains.DocumentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.Impl;
using JetBrains.ReSharper.Daemon.Specific.NamingConsistencyCheck;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;

[assembly: RegisterConfigurableSeverity(
	DpFieldMustEndWithPropertyHighlighting.SeverityId,
	null,
	HighlightingGroupIds.CodeSmell,
	DpFieldMustEndWithPropertyHighlighting.Description,
	DpFieldMustEndWithPropertyHighlighting.Description,
	Severity.WARNING,
	false)]

namespace GammaJul.ReSharper.GammaXaml.Highlightings.CSharp {

	/// <summary>
	/// An highlighting that represent a DependencyProperty field registration that doesn't end with Property.
	/// </summary>
	[ConfigurableSeverityHighlighting(SeverityId, CSharpProjectFileType.Name, OverlapResolve = OverlapResolveKind.WARNING)]
	public class DpFieldMustEndWithPropertyHighlighting : InconsistentNamingWarning, IHighlightingWithRange {
		internal const string SeverityId = "Dp.FieldMustEndWithProperty";
		internal const string Description = "Dependency property field name must end with Property.";

		private readonly IFieldDeclaration _dpFieldDeclaration;

		public new string ToolTip {
			get { return Description; }
		}

		public new string ErrorStripeToolTip {
			get { return Description; }
		}

		public DocumentRange CalculateRange() {
			return _dpFieldDeclaration.NameIdentifier.GetHighlightingRange();
		}

		public DpFieldMustEndWithPropertyHighlighting([NotNull] IFieldDeclaration dpFieldDeclaration, [NotNull] IPsiSourceFile sourceFile)
			: base(dpFieldDeclaration.DeclaredElement, dpFieldDeclaration.DeclaredName, null, dpFieldDeclaration.DeclaredName.ToDpFieldName(), sourceFile) {
			if (dpFieldDeclaration == null)
				throw new ArgumentNullException("dpFieldDeclaration");
			if (sourceFile == null)
				throw new ArgumentNullException("sourceFile");

			_dpFieldDeclaration = dpFieldDeclaration;
		}
	}

}
